package Jogo.States {
	import Jogo.Main;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.net.URLRequest;
	import flash.system.System;
	
	import mx.core.UIComponent;
	
	import spark.components.Button;
	
	/** State that controls the main manu of the game
	 * 
	 * @author Bruno Zumba (27/07/2011)
	 */
	public class MenuState extends State {
		/* Pictures */
		[Embed(source = "../../Img/Menu/MenuBG.png")]
		private var bgBMP:Class; //Background
		private var bg : Bitmap;
		private var bgP : Point = new Point(0,0);
		
		[Embed(source = "../../Img/Menu/CreditosBG.png")]
		private var creditosBgBMP:Class; //Start button
		private var creditosBgImg : Bitmap;
		private var creditosBgP : Point = new Point(0, 0);
		private var creditosBg : MovieClip;
		
		[Embed(source = "../../Img/Menu/MenuStartBt.png")]
		private var startBtBMP:Class; //Start button
		private var startBtImg : Bitmap;
		private var startBtP : Point = new Point(384, 400);
		private var startBt : MovieClip;
		
		[Embed(source = "../../Img/Menu/MenuCreditosBt.png")]
		private var creditosBtBMP:Class; 
		private var creditosBtImg : Bitmap;
		private var creditosBtP : Point = new Point(384, 500);
		private var creditosBt : MovieClip;
		
		[Embed(source = "../../Img/Menu/MenuSairBt.png")]
		private var sairBtBMP:Class; 
		private var sairBtImg : Bitmap;
		private var sairBtP : Point = new Point(384, 600);
		private var sairBt : MovieClip;
		
		private var mainInstance : Main;
		
		public function MenuState()	{
			root = new MovieClip();
			
			mainInstance = Main.getInstance();
			
			bg = new bgBMP();
			bg.x = bgP.x; bg.y = bgP.y;
			
			startBtImg = new startBtBMP();
			startBt = new MovieClip();
			startBt.x = startBtP.x; startBt.y = startBtP.y;
			startBt.addChild(startBtImg);
			
			creditosBtImg = new creditosBtBMP();
			creditosBt = new MovieClip();
			creditosBt.x = creditosBtP.x; creditosBt.y = creditosBtP.y;
			creditosBt.addChild(creditosBtImg);
			
			sairBtImg = new sairBtBMP();
			sairBt = new MovieClip();
			sairBt.x = sairBtP.x; sairBt.y = sairBtP.y;
			sairBt.addChild(sairBtImg);
			
			creditosBgImg = new creditosBgBMP();
			creditosBg = new MovieClip();
			creditosBg.x = creditosBgP.x; creditosBg.y = creditosBgP.y;
			creditosBg.addChild(creditosBgImg);
			
			
			startBt.addEventListener(MouseEvent.CLICK, startBtClicked);
			creditosBt.addEventListener(MouseEvent.CLICK, creditosBtClicked);
			sairBt.addEventListener(MouseEvent.CLICK, sairBtClicked);
			
		}
		
		private function startBtClicked(e:MouseEvent):void{
			mainInstance.setState(Main.ST_PHASE1);
		}
		
		private function sairBtClicked(e:MouseEvent):void{
			mainInstance.exit(null);
		}
		
		
		private function creditosBtClicked(e:MouseEvent):void{
			root.removeChild(startBt);
			root.removeChild(creditosBt);
			root.removeChild(bg);
			root.removeChild(sairBt);
			
			root.addChild(creditosBg);
			creditosBg.addEventListener(MouseEvent.CLICK, creditosBgClicked);
		}
		
		private function creditosBgClicked(e:MouseEvent):void{
			root.removeChild(creditosBg);
			
			root.addChild(bg);
			root.addChild(startBt);
			root.addChild(creditosBt);
			root.addChild(sairBt);
		}
		
		
		override public function assume(previousState : State) : void {
			if (previousState != null){
				mainInstance.removeGraphics(previousState.getGraphicsRoot());
			}
			
			root.addChild(bg);
			root.addChild(startBt);
			root.addChild(creditosBt);
			root.addChild(sairBt);
			
			mainInstance.addGraphics(root);
		}

		override public function reassume(previousState : State) : void {
		}
		
		override public function leave() : void {
		}
		
		override public function enterFrame(e : Event) : void {
		}
	}
}